import time
from selenium.webdriver.common.by import By
from base import BasePage, BaseHandle


class HomePage(BasePage):
    def __init__(self):
        super().__init__()
        self.quit_info = (By.PARTIAL_LINK_TEXT, "退出")
        self.content_manage = (By.XPATH, "//*[@class='side_bar']/ul/li[3]/a")
        self.content_audit = (By.XPATH, "//*[@class='current']/li[3]/a")

    def find_quit_info(self):
        return self.get_element(self.quit_info)

    def find_content_manage(self):
        return self.get_element(self.content_manage)

    def find_content_audit(self):
        return self.get_element(self.content_audit)


class HomeHandle(BaseHandle):
    def __init__(self):
        self.home_page = HomePage()

    def get_quit_info(self):
        return self.home_page.find_quit_info().text

    def click_content_manage(self):
        self.home_page.find_content_manage().click()

    def click_content_audit(self):
        self.home_page.find_content_audit().click()


class HomeProxy:
    def __init__(self):
        self.home_handle = HomeHandle()

    def get_quit(self):
        return self.home_handle.get_quit_info()

    def go_content_audit(self):
        self.home_handle.click_content_manage()
        time.sleep(1)
        self.home_handle.click_content_audit()